﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmallERP.COM;
using SmallERP.DAL;
using SmallERP.MODEL.FoundationModel;

namespace SmallERP.Bll.Com
{
    public class PaperWasteRecordsBll
    {
        public List<PaperWasteRecord_info> GetListWaste(int inWasteId)
        {
            List<PaperWasteRecord_info> rtnList = new List<PaperWasteRecord_info>();
            //using (smallerpDataContext db = new smallerpDataContext())
            //{
            //    PaperWasteRecords paperWasteRecord = db.PaperWasteRecords.FirstOrDefault(p => p.Id == inWasteId);
            //    List<PaperWasteRecords> listRecod =
            //        db.PaperWasteRecords.Where(p => p.PaperInfo.PrintPaperId == paperWasteRecord.PaperInfo.PrintPaperId)
            //            .ToList();
            //    PaperWasteRecord_info info;
            //    foreach (PaperWasteRecords list in listRecod)
            //    {
            //        info = new PaperWasteRecord_info();
            //        info.CreateTime = UnityMethod.GetSystemTime();
            //        info.Id = list.Id;
            //        info.Length = list.Length;
            //        if (!list.PaperInfoReference.IsLoaded)
            //        {
            //            list.PaperInfoReference.Load();
            //        }
            //        info.PaperInfo = new PaperInfo_info() { AddTime = list.PaperInfo.AddTime, EndPaperLength = list.PaperInfo.EndPaperLength, InvalidationArea = list.PaperInfo.InvalidationArea, LastBordId = list.PaperInfo.LastBordId, LastLength = list.PaperInfo.LastLength, LastPrintTime = info.PaperInfo.LastPrintTime, Length = list.PaperInfo.Length, PaperConsumptionLength = list.PaperInfo.PaperConsumptionLength, PaperEndArea = list.PaperInfo.PaperEndArea };
            //        // info.PaperWasteTypeId = list.PaperWasteType.Id;
            //        if (!list.PaperWasteTypeReference.IsLoaded)
            //        {
            //            list.PaperWasteTypeReference.Load();
            //        }
            //        info.PaperWasteType = new PaperWasteType_info() { Id = list.PaperWasteType.Id, PaperOperationTypeName = list.PaperWasteType.PaperOperationTypeName };
            //        info.Remark = list.Remark;
            //        info.Status = list.Status;
            //        info.Width = list.Width;
            //        // info.Length
            //        rtnList.Add(info);

            //    }
            //}
            return rtnList;
        }
        public List<PaperWasteRecord_info> MakeSureRecord(int inWasteId)
        {

            List<PaperWasteRecord_info> rtnList = new List<PaperWasteRecord_info>();
            //using (smallerpDataContext db = new smallerpDataContext())
            //{
            //    PaperWasteRecords paperWasteRecord = db.PaperWasteRecords.FirstOrDefault(p => p.Id == inWasteId);
            //    if (paperWasteRecord==null)
            //    {
            //        return new List<PaperWasteRecord_info>();
            //    }
            //    paperWasteRecord.Status = (int)Status.WasterPaperStatus.Sure;
            //    paperWasteRecord.PaperInfoReference.Load();
            //    List<PaperWasteRecords> listRecod =
            //        db.PaperWasteRecords.Where(p => p.PaperInfo.PrintPaperId == paperWasteRecord.PaperInfo.PrintPaperId)
            //            .ToList();
            //    PaperWasteRecord_info info;
            //    foreach (PaperWasteRecords list in listRecod)
            //    {
            //        info = new PaperWasteRecord_info();
            //        info.CreateTime = UnityMethod.GetSystemTime();
            //        info.Id = list.Id;
            //        info.Length = list.Length;
            //        if (!list.PaperInfoReference.IsLoaded)
            //        {
            //            list.PaperInfoReference.Load();
            //        }
            //        //info.PaperInfo = new PaperInfo_info() { AddTime = list.PaperInfo.AddTime, EndPaperLength = list.PaperInfo.EndPaperLength, InvalidationArea = list.PaperInfo.InvalidationArea, LastBordId = list.PaperInfo.LastBordId, LastLength = list.PaperInfo.LastLength, LastPrintTime = info.PaperInfo.LastPrintTime, Length = list.PaperInfo.Length, PaperConsumptionLength = list.PaperInfo.PaperConsumptionLength, PaperEndArea = list.PaperInfo.PaperEndArea };
            //        // info.PaperWasteTypeId = list.PaperWasteType.Id;
            //        //info.PaperInfo=new PaperInfo_info();
            //         PaperInfo_info paperinfo=new PaperInfo_info();

            //        {
            //            paperinfo.AddTime = list.PaperInfo.AddTime;
            //            paperinfo.EndPaperLength = list.PaperInfo.EndPaperLength;
            //            paperinfo.InvalidationArea = list.PaperInfo.InvalidationArea;
            //            paperinfo.LastBordId = list.PaperInfo.LastBordId;
            //            paperinfo.LastLength = list.PaperInfo.LastLength;
            //            paperinfo.LastPrintTime = list.PaperInfo.LastPrintTime;
            //            paperinfo.Length = list.PaperInfo.Length;
            //            ;
            //            paperinfo.PaperConsumptionLength = list.PaperInfo.PaperConsumptionLength;

            //            paperinfo.PaperEndArea = list.PaperInfo.PaperEndArea;
            //            paperinfo.PrintPaperId = list.PaperInfo.PrintPaperId;
            //        }
            //        info.PaperInfo = paperinfo;
            //        if (!list.PaperWasteTypeReference.IsLoaded)
            //        {
            //            list.PaperWasteTypeReference.Load();
            //        }
            //        info.PaperWasteType = new PaperWasteType_info() { Id = list.PaperWasteType.Id, PaperOperationTypeName = list.PaperWasteType.PaperOperationTypeName };
            //        info.Remark = list.Remark;
            //        info.Status = list.Status;
            //        info.Width = list.Width;
            //        // info.Length
            //        db.SaveChanges();
            //        rtnList.Add(info);

            //    }
            //}
            return rtnList;
        }
        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="inWasteId"></param>
        /// <returns></returns>
        public bool MakeSureRecordSinger(int inWasteId)
        {
            //try
            //{

           
            //using (smallerpDataContext db = new smallerpDataContext())
            //{
            //    PaperWasteRecords list = db.PaperWasteRecords.FirstOrDefault(p => p.Id == inWasteId);
            //    if (list.Status != (int)Status.WasterPaperStatus.Sure)
            //    {
            //        list.Status = (int)Status.WasterPaperStatus.Sure;
            //    }
            //    db.SaveChanges();

            //}
            //}
            //catch 
            //{

            //    return false;
            //}
            return true;

        }
    }
}
